package com.ssm.modules.controller;

import com.ssm.common.bean.VResponse;
import com.ssm.modules.entity.Role;
import com.ssm.modules.service.IRoleService;
import com.ssm.modules.service.impl.RoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.PUT;
import java.util.List;

/**
 * @email:
 * @author:
 * @date: 2018/12/18
 * @time: 17:24
 * 角色Controller
 */
@Controller
public class RoleController {
    @Autowired
    private IRoleService roleService;
    @ResponseBody
    @RequestMapping(value = "/selectRole",method = RequestMethod.GET)
    public VResponse<List<Role>> selectRolee() {
        List<Role> roles = roleService.findAllRole();
        return VResponse.success(roles);
    }
    @ResponseBody
    @RequestMapping(value = "/addRole", method = RequestMethod.POST)
    public VResponse <Object> addRoleSubmit(@RequestBody Role role){
        roleService.addRole(role);
        VResponse.error(0, "添加失败");
        return VResponse.success("添加成功");
    }
    @ResponseBody
    @RequestMapping(value = "/updateRole",method = RequestMethod.PUT)
    public VResponse<Object> updateRole(@RequestBody Role role){
        this.roleService.updateRole(role);
        return VResponse.success("修改成功");
    }
    @ResponseBody
    @RequestMapping(value = "/deleteRole",method = RequestMethod.DELETE)
    public VResponse<Object>deleteRole(@RequestParam("id") int id){
        this.roleService.deleteRole(id);
        return VResponse.success("删除成功");
    }
}
